package gavdi.dk.view;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import gavdi.dk.controller.LoginController;
import gavdi.dk.data.DAOAbsence;
import gavdi.dk.data.DAOEvent;
import gavdi.dk.data.DAORecentWBS;
import gavdi.dk.data.DAOUser;
import gavdi.dk.model.Absence;
import gavdi.dk.model.AbsenceRegistration;
import gavdi.dk.model.Customer;
import gavdi.dk.model.Event;
import gavdi.dk.model.RecentWBS;
import gavdi.dk.model.TimeRegistration;
import gavdi.dk.model.User;
import gavdi.dk.util.Tools;
import gavdi.dk.view.R;
import Exceptions.ConverterException;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff.Mode;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

public class RegistrationActivity extends Activity implements OnClickListener {

	private TextView lblDate;

	private Button btnMyWBS;
	private Button btnShowAllWBS;
	private Button btnShowAllCodes;

	private Button btnSubmitRegistration;
	private Button btnTimeRegistration;
	private Button btnAbsenceRegistration;
	private Button btnFullDay;
	private Button btnHalfDay;
	private Button btnTwoHours;
	private Button btnCustomHours;

	private Button btnRecentWBS1;
	private Button btnRecentWBS2;
	private Button btnRecentWBS3;
	private Button btnRecentWBS4;
	private Button btnRecentWBS5;
	private Button btnRecentWBS6;

	private Button btnAbsence1;
	private Button btnAbsence2;
	private Button btnAbsence3;
	private Button btnAbsence4;
	private Button btnAbsence5;
	private Button btnAbsence6;

	private LinearLayout listBasket;
	private LinearLayout layoutTime;
	private LinearLayout layoutAbsence;
	private String customerName;
	private String type;
	private String hours;
	private String WBSorCode;
	private String date;
	private String userID;
	private ArrayList<Event> tempEvent;
	private Customer customer;
	private DAOUser dUser;

	private Bundle bundle;
	private DAOAbsence dAbsence;
	private DAORecentWBS dRecentWBS;

	private ArrayList<Button> recentButtons;
	private ArrayList<Button> absenceButtons;
	private ArrayList<RecentWBS> recentwbss;
	private ArrayList<Absence> absence;

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		System.out.println("kommer den tilbage?");

		if (resultCode == RESULT_CANCELED) {

		}
		if (resultCode == RESULT_OK) {
			if (requestCode == 1) {
				// MY WBS
				System.out.println("nu er jeg tilbage "
						+ data.getExtras().getInt("index"));

				customerName = data.getExtras().getString("name");
				WBSorCode = data.getExtras().getString("WBSorCode");

				resetbtnRecent();
				btnMyWBS.getBackground().setColorFilter(
						Color.parseColor("#008B45"), Mode.MULTIPLY);

				createViewForBasket();

			}
			if (requestCode == 2) {
				// ALL WBS

				resetbtnRecent();
				System.out.println("nu er jeg tilbage "
						+ data.getExtras().getInt("index"));
				customerName = data.getExtras().getString("name");
				WBSorCode = data.getExtras().getString("WBSorCode");
				btnShowAllWBS.getBackground().setColorFilter(
						Color.parseColor("#008B45"), Mode.MULTIPLY);

				createViewForBasket();

			}
			if (requestCode == 3) {
				// ALL CODES

				resetbtnAbsence();
				System.out.println("nu er jeg tilbage "
						+ data.getExtras().getInt("index"));
				customerName = data.getExtras().getString("name");
				WBSorCode = data.getExtras().getString("WBSorCode");
				btnShowAllCodes.getBackground().setColorFilter(
						Color.parseColor("#008B45"), Mode.MULTIPLY);

				createViewForBasket();

			}

			if (requestCode == 4) {
				// ALL CODES

				resetbtnAbsence();
				hours = data.getExtras().getString("hours");
				btnCustomHours.getBackground().setColorFilter(
						Color.parseColor("#008B45"), Mode.MULTIPLY);

				btnFullDay.getBackground().setColorFilter(Color.LTGRAY,
						Mode.MULTIPLY);
				btnHalfDay.getBackground().setColorFilter(Color.LTGRAY,
						Mode.MULTIPLY);
				btnTwoHours.getBackground().setColorFilter(Color.LTGRAY,
						Mode.MULTIPLY);
				createViewForBasket();

			}

		}

	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.registration_layout);
		initAttributes();
		super.onCreate(savedInstanceState);

		System.out.println("WHAT DATE: " + date);

		setListener();

		btnTimeRegistration.getBackground().setColorFilter(
				Color.parseColor("#008B45"), Mode.MULTIPLY);

		lblDate.setText(date);

		btnMyWBS.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent(getBaseContext(), WBSActivity.class);
				bundle.putString("WBSorCode", "myWBS");
				intent.putExtras(bundle);
				// startActivity(intent);
				startActivityForResult(intent, 1);

			}
		});
		btnShowAllWBS.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent(getBaseContext(), WBSActivity.class);
				bundle.putString("WBSorCode", "showAllWBS");
				intent.putExtras(bundle);
				startActivityForResult(intent, 2);

			}
		});

		btnShowAllCodes.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent(getBaseContext(), WBSActivity.class);
				bundle.putString("WBSorCode", "showAllCodes");
				intent.putExtras(bundle);
				startActivityForResult(intent, 3);

			}
		});

		btnSubmitRegistration.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {

				DAOEvent dEvent = new DAOEvent(getBaseContext());

				if (Tools.isInternetOn(getBaseContext())) {

					// INTERNET IS AVAILABLE, DO STUFF..

					for (Event e : tempEvent) {

						try {
							Tools.createTimeRegJSON(e.getUserID(), "WBSorCode",
									e.getDate(), e.getHours());
							dEvent.createEvent(e, userID);
						} catch (ConverterException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}

					}

					System.out.println("INTERNET AVAIBLE");

				} else {
					System.out.println("INTERNET NOT AVAIBLE");
					for (Event e : tempEvent) {

						dEvent.createEvent(e, userID);

					}

					// NO INTERNET AVAILABLE, DO STUFF..

				}

				Intent intent = new Intent(getBaseContext(), MenuActivity.class);
				intent.putExtras(bundle);
				startActivity(intent);

			}
		});

		btnCustomHours.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent(getBaseContext(),
						CustomHoursActivity.class);
				intent.putExtras(bundle);
				startActivityForResult(intent, 4);

			}
		});

	}

	public void onClick(View v) {
		// v.setBackgroundColor(Color.parseColor("#008B45"));

		startRegistrationFunction(v);
		startHoursFunction(v);
		startWBSFunction(v);
		startCodeFunction(v);
		createViewForBasket();

	}

	private void startRegistrationFunction(View v) {
		// Choose Time Registration or AbsenceRegistration
		if (v == btnTimeRegistration || v == btnAbsenceRegistration) {
			if (v == btnTimeRegistration) {
				type = "T";
				layoutTime.setVisibility(View.VISIBLE);
				layoutAbsence.setVisibility(View.GONE);

			}
			if (v == btnAbsenceRegistration) {
				type = "A";
				layoutTime.setVisibility(View.GONE);
				layoutAbsence.setVisibility(View.VISIBLE);
			}

			btnTimeRegistration.getBackground().setColorFilter(Color.LTGRAY,
					Mode.MULTIPLY);
			btnAbsenceRegistration.getBackground().setColorFilter(Color.LTGRAY,
					Mode.MULTIPLY);
			v.getBackground().setColorFilter(Color.parseColor("#008B45"),
					Mode.MULTIPLY);
		}

	}

	private void startHoursFunction(View v) {
		if (v == btnFullDay || v == btnHalfDay || v == btnTwoHours) {
			btnFullDay.getBackground().setColorFilter(Color.LTGRAY,
					Mode.MULTIPLY);
			btnHalfDay.getBackground().setColorFilter(Color.LTGRAY,
					Mode.MULTIPLY);
			btnTwoHours.getBackground().setColorFilter(Color.LTGRAY,
					Mode.MULTIPLY);
			btnCustomHours.getBackground().setColorFilter(Color.LTGRAY,
					Mode.MULTIPLY);

			v.getBackground().setColorFilter(Color.parseColor("#008B45"),
					Mode.MULTIPLY);
		}
		if (v == btnFullDay) {
			hours = "450";
		} else if (v == btnHalfDay) {
			hours = "225";
		} else if (v == btnTwoHours) {
			hours = "120";
		}
	}

	private void startWBSFunction(View v) {
		if (v == btnRecentWBS1 || v == btnRecentWBS2 || v == btnRecentWBS3
				|| v == btnRecentWBS4 || v == btnRecentWBS5
				|| v == btnRecentWBS6) {

			resetbtnRecent();
			v.getBackground().setColorFilter(Color.parseColor("#008B45"),
					Mode.MULTIPLY);

			if (v == btnMyWBS || v == btnShowAllWBS) {

			}

			RecentWBS recentwbs = (RecentWBS) v.getTag();
			WBSorCode = recentwbs.getWBS();
			customerName = recentwbs.getCustomer().getName();
		}

	}

	private void startCodeFunction(View v) {
		if (v == btnAbsence1 || v == btnAbsence2 || v == btnAbsence3
				|| v == btnAbsence4 || v == btnAbsence5 || v == btnAbsence6) {

			resetbtnAbsence();
			v.getBackground().setColorFilter(Color.parseColor("#008B45"),
					Mode.MULTIPLY);

			if (v == btnShowAllCodes) {

			}

			Absence abs = (Absence) v.getTag();
			WBSorCode = abs.getCode();
			customerName = abs.getName();

		}

	}

	private void createViewForBasket() {

		if (type != "" && hours != "" && WBSorCode != "") {

			final LinearLayout ll = new LinearLayout(this);

			TextView tvName = new TextView(this);
			TextView tvWBSorCode = new TextView(this);
			TextView tvHours = new TextView(this);
			final ImageButton btnRemoveFromBasket = new ImageButton(this);

			LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
					LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
			params.weight = 0.25f;

			tvName.setLayoutParams(params);
			tvWBSorCode.setLayoutParams(params);
			tvHours.setLayoutParams(params);
			btnRemoveFromBasket.setLayoutParams(params);
			btnRemoveFromBasket
					.setImageResource(android.R.drawable.ic_menu_delete);

			tvName.setTextSize(20);
			// tvName.setPadding(0, 0, 20, 0);

			tvWBSorCode.setTextSize(20);
			tvHours.setTextSize(20);

			tvName.setText(customerName);
			tvWBSorCode.setText(WBSorCode);

			double hours1 = (Double.parseDouble(hours) / 60);
			tvHours.setText("" + hours1);

			ll.addView(tvName);
			ll.addView(tvWBSorCode);
			ll.addView(tvHours);
			ll.addView(btnRemoveFromBasket);

			listBasket.addView(ll);

			createTempEvent(type, WBSorCode, hours, customerName,
					btnRemoveFromBasket);

			btnRemoveFromBasket.setOnClickListener(new View.OnClickListener() {

				public void onClick(View v) {
					System.out.println(v.getTag());
					tempEvent.remove(v.getTag());
					listBasket.removeView((View) btnRemoveFromBasket
							.getParent());

				}
			});

			resetButtons();

		}

	}

	private void createAllsViewsForBasket() {
		for (Event e : tempEvent) {

			final LinearLayout ll = new LinearLayout(this);

			TextView tvName = new TextView(this);
			TextView tvWBSorCode = new TextView(this);
			TextView tvHours = new TextView(this);
			final ImageButton btnRemoveFromBasket = new ImageButton(this);

			type = e.getType();
			if (type.equalsIgnoreCase("T")) {
				TimeRegistration tr = (TimeRegistration) e;
				WBSorCode = tr.getCustomer().getWbs();
				customerName = tr.getCustomer().getName();
				btnRemoveFromBasket.setTag(tr);
			} else if (type.equalsIgnoreCase("A")) {
				AbsenceRegistration ab = (AbsenceRegistration) e;
				WBSorCode = ab.getAbsence().getCode();
				customerName = ab.getAbsence().getName();
				btnRemoveFromBasket.setTag(ab);
			}
			hours = e.getHours();

			LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
					LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
			params.weight = 0.25f;

			tvName.setLayoutParams(params);
			tvWBSorCode.setLayoutParams(params);
			tvHours.setLayoutParams(params);
			btnRemoveFromBasket.setLayoutParams(params);
			btnRemoveFromBasket
					.setImageResource(android.R.drawable.ic_menu_delete);

			tvName.setTextSize(20);
			// tvName.setPadding(0, 0, 20, 0);

			tvWBSorCode.setTextSize(20);
			tvHours.setTextSize(20);

			tvName.setText(customerName);
			tvWBSorCode.setText(WBSorCode);

			double hours1 = (Double.parseDouble(hours) / 60);
			tvHours.setText("" + hours1);

			ll.addView(tvName);
			ll.addView(tvWBSorCode);
			ll.addView(tvHours);
			ll.addView(btnRemoveFromBasket);

			listBasket.addView(ll);

			btnRemoveFromBasket.setOnClickListener(new View.OnClickListener() {

				public void onClick(View v) {
					System.out.println(v.getTag());
					tempEvent.remove(v.getTag());
					listBasket.removeView((View) btnRemoveFromBasket
							.getParent());

				}

			});

			resetButtons();

		}

	}

	private void createTempEvent(String type, String WBSorCode, String hours,
			String name, ImageButton btnRemoveFromBasket) {
		if (type.equalsIgnoreCase("T")) {
			TimeRegistration tr = new TimeRegistration();
			Customer customer = new Customer();
			customer.setWbs(WBSorCode);
			customer.setName(name);

			tr.setCustomer(customer);

			tr.setUserID(userID);
			tr.setDate(Tools.dateRemovedSplitter(date));
			tr.setStatus("Pending");
			tr.setType(type);
			tr.setComment("");
			tr.setHours(hours);

			tempEvent.add(tr);
			btnRemoveFromBasket.setTag(tr);
		}
		if (type.equalsIgnoreCase("A")) {
			AbsenceRegistration ar = new AbsenceRegistration();
			Absence absence = new Absence();
			absence.setCode(WBSorCode);
			absence.setName(name);

			ar.setAbsence(absence);

			ar.setUserID(userID);
			ar.setDate(Tools.dateRemovedSplitter(date));
			ar.setStatus("Pending");
			ar.setType(type);
			ar.setComment("");
			ar.setHours(hours);
			ar.setId("");

			tempEvent.add(ar);
			btnRemoveFromBasket.setTag(ar);
		}
	}

	private void setListener() {
		btnTimeRegistration.setOnClickListener(this);
		btnAbsenceRegistration.setOnClickListener(this);

		btnFullDay.setOnClickListener(this);
		btnHalfDay.setOnClickListener(this);
		btnTwoHours.setOnClickListener(this);

		btnRecentWBS1.setOnClickListener(this);
		btnRecentWBS2.setOnClickListener(this);
		btnRecentWBS3.setOnClickListener(this);
		btnRecentWBS4.setOnClickListener(this);
		btnRecentWBS5.setOnClickListener(this);
		btnRecentWBS6.setOnClickListener(this);

		btnAbsence1.setOnClickListener(this);
		btnAbsence2.setOnClickListener(this);
		btnAbsence3.setOnClickListener(this);
		btnAbsence4.setOnClickListener(this);
		btnAbsence5.setOnClickListener(this);
		btnAbsence6.setOnClickListener(this);
	}

	private void resetbtnAbsence() {
		btnAbsence1.getBackground().setColorFilter(Color.LTGRAY, Mode.MULTIPLY);
		btnAbsence2.getBackground().setColorFilter(Color.LTGRAY, Mode.MULTIPLY);
		btnAbsence3.getBackground().setColorFilter(Color.LTGRAY, Mode.MULTIPLY);
		btnAbsence4.getBackground().setColorFilter(Color.LTGRAY, Mode.MULTIPLY);
		btnAbsence5.getBackground().setColorFilter(Color.LTGRAY, Mode.MULTIPLY);
		btnAbsence6.getBackground().setColorFilter(Color.LTGRAY, Mode.MULTIPLY);
		btnShowAllCodes.getBackground().setColorFilter(Color.LTGRAY,
				Mode.MULTIPLY);
	}

	private void resetbtnRecent() {
		btnRecentWBS1.getBackground().setColorFilter(Color.LTGRAY,
				Mode.MULTIPLY);
		btnRecentWBS2.getBackground().setColorFilter(Color.LTGRAY,
				Mode.MULTIPLY);
		btnRecentWBS3.getBackground().setColorFilter(Color.LTGRAY,
				Mode.MULTIPLY);
		btnRecentWBS4.getBackground().setColorFilter(Color.LTGRAY,
				Mode.MULTIPLY);
		btnRecentWBS5.getBackground().setColorFilter(Color.LTGRAY,
				Mode.MULTIPLY);
		btnRecentWBS6.getBackground().setColorFilter(Color.LTGRAY,
				Mode.MULTIPLY);
		btnMyWBS.getBackground().setColorFilter(Color.LTGRAY, Mode.MULTIPLY);
		btnShowAllWBS.getBackground().setColorFilter(Color.LTGRAY,
				Mode.MULTIPLY);
	}

	private void resetButtons() {

		btnTimeRegistration.getBackground().setColorFilter(
				Color.parseColor("#008B45"), Mode.MULTIPLY);
		btnAbsenceRegistration.getBackground().setColorFilter(Color.LTGRAY,
				Mode.MULTIPLY);
		btnFullDay.getBackground().setColorFilter(Color.LTGRAY, Mode.MULTIPLY);
		btnHalfDay.getBackground().setColorFilter(Color.LTGRAY, Mode.MULTIPLY);
		btnTwoHours.getBackground().setColorFilter(Color.LTGRAY, Mode.MULTIPLY);
		btnCustomHours.getBackground().setColorFilter(Color.LTGRAY,
				Mode.MULTIPLY);

		resetbtnRecent();
		resetbtnAbsence();

		btnMyWBS.getBackground().setColorFilter(Color.LTGRAY, Mode.MULTIPLY);
		btnShowAllWBS.getBackground().setColorFilter(Color.LTGRAY,
				Mode.MULTIPLY);
		btnShowAllCodes.getBackground().setColorFilter(Color.LTGRAY,
				Mode.MULTIPLY);

		type = "T";
		hours = "";
		WBSorCode = "";
		customerName = "";

	}

	private void initAttributes() {
		lblDate = (TextView) findViewById(R.id.lblDate);

		btnMyWBS = (Button) findViewById(R.id.btnMyWBS);

		btnShowAllWBS = (Button) findViewById(R.id.btnShowAllWBS);
		btnShowAllCodes = (Button) findViewById(R.id.btnShowAllAbsence);

		btnSubmitRegistration = (Button) findViewById(R.id.btnSubmitRegistration);
		btnTimeRegistration = (Button) findViewById(R.id.btnTimeRegistration);
		btnAbsenceRegistration = (Button) findViewById(R.id.btnAbsenceRegistration);
		tempEvent = new ArrayList<Event>();

		btnFullDay = (Button) findViewById(R.id.btnFullDay);

		btnHalfDay = (Button) findViewById(R.id.btnHalfDay);

		btnTwoHours = (Button) findViewById(R.id.btnTwoHours);

		btnCustomHours = (Button) findViewById(R.id.btnCustomHours);

		btnRecentWBS1 = (Button) findViewById(R.id.btnRecentWBS1);
		btnRecentWBS2 = (Button) findViewById(R.id.btnRecentWBS2);
		btnRecentWBS3 = (Button) findViewById(R.id.btnRecentWBS3);
		btnRecentWBS4 = (Button) findViewById(R.id.btnRecentWBS4);
		btnRecentWBS5 = (Button) findViewById(R.id.btnRecentWBS5);
		btnRecentWBS6 = (Button) findViewById(R.id.btnRecentWBS6);

		btnAbsence1 = (Button) findViewById(R.id.btnAbsence1);
		btnAbsence2 = (Button) findViewById(R.id.btnAbsence2);
		btnAbsence3 = (Button) findViewById(R.id.btnAbsence3);
		btnAbsence4 = (Button) findViewById(R.id.btnAbsence4);
		btnAbsence5 = (Button) findViewById(R.id.btnAbsence5);
		btnAbsence6 = (Button) findViewById(R.id.btnAbsence6);

		listBasket = (LinearLayout) findViewById(R.id.listBasket);
		layoutTime = (LinearLayout) findViewById(R.id.layoutTime);
		layoutAbsence = (LinearLayout) findViewById(R.id.layoutAbsence);

		type = "T";
		hours = "";
		WBSorCode = "";
		customerName = "";

		dUser = new DAOUser(getBaseContext());

		bundle = getIntent().getExtras();
		date = bundle.getString("date");
		userID = bundle.getString("userID");

		dAbsence = new DAOAbsence(getBaseContext());
		dRecentWBS = new DAORecentWBS(getBaseContext());
		recentwbss = dRecentWBS.getAllRecentWBSbyUserID(userID);
		absence = dAbsence.getAllAbsence();

		initRecentButtons();
		initAbsenceButtons();

	}

	public void initRecentButtons() {
		recentButtons = new ArrayList<Button>();
		recentButtons.add(btnRecentWBS1);
		recentButtons.add(btnRecentWBS2);
		recentButtons.add(btnRecentWBS3);
		recentButtons.add(btnRecentWBS4);
		recentButtons.add(btnRecentWBS5);
		recentButtons.add(btnRecentWBS6);

		for (int i = 0; i < recentButtons.size(); i++) {

			if (i < recentwbss.size()) {
				recentButtons.get(i).setText(
						recentwbss.get(i).getCustomer().getName());
				recentButtons.get(i).setTag(recentwbss.get(i));
			} else {
				recentButtons.get(i).setText("Empty");
				recentButtons.get(i).setEnabled(false);
				recentButtons.get(i).setClickable(false);
			}
		}
	}

	public void initAbsenceButtons() {
		absenceButtons = new ArrayList<Button>();
		absenceButtons.add(btnAbsence1);
		absenceButtons.add(btnAbsence2);
		absenceButtons.add(btnAbsence3);
		absenceButtons.add(btnAbsence4);
		absenceButtons.add(btnAbsence5);
		absenceButtons.add(btnAbsence6);

		for (int i = 0; i < absenceButtons.size(); i++) {

			if (i < absence.size()) {
				absenceButtons.get(i).setText(absence.get(i).getName());
				absenceButtons.get(i).setTag(absence.get(i));
			} else {
				absenceButtons.get(i).setText("Empty");
				absenceButtons.get(i).setEnabled(false);
				absenceButtons.get(i).setClickable(false);
			}
		}
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		// --- save whatever you need to persist---

		outState.putString("customerName", customerName);
		outState.putString("type", type);
		outState.putString("hours", hours);
		outState.putString("WBSorCode", WBSorCode);
		outState.putString("date", date);
		outState.putString("userID", userID);
		outState.putBundle("bundle", bundle);
		outState.putSerializable("tempEvent", tempEvent);
		outState.putSerializable("recentwbss", recentwbss);
		outState.putSerializable("absence", absence);

		super.onSaveInstanceState(outState);

	}

	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		// ---retrieve the information persisted earlier---

		super.onRestoreInstanceState(savedInstanceState);

		bundle = savedInstanceState.getBundle("bundle");
		customerName = savedInstanceState.getString("customerName");

		date = savedInstanceState.getString("date");
		userID = savedInstanceState.getString("userID");
		tempEvent = (ArrayList<Event>) savedInstanceState
				.getSerializable("tempEvent");
		recentwbss = (ArrayList<RecentWBS>) savedInstanceState
				.getSerializable("recentwbss");
		absence = (ArrayList<Absence>) savedInstanceState
				.getSerializable("absence");

		System.out.println("Temp even items: " + tempEvent.size());

		createAllsViewsForBasket();

		type = savedInstanceState.getString("type");
		hours = savedInstanceState.getString("hours");
		WBSorCode = savedInstanceState.getString("WBSorCode");

		System.out.println("Items in basket: " + listBasket.getChildCount());

		// bundle = savedInstanceState.getBundle("bundle");

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.registration_layout, menu);
		return true;
	}

}
